# # num_one = 1
# # 使用海象运算符为num_two赋值
# # result = num_one + (num_two := 2)
# # print(result)
#
# if 5 > 12:
#     print("5 is greater than 12")
#     print("222222")
# else:
#     print("5 is not greater than 12")
#
# age = 20
# if age < 18:
#     print("You are underaged")
#     # &&不可用
# elif age >= 18 and age < 30:
#     print("You are young")
# elif age >= 30 and age < 50:
#     print("You are middle-age")
# else:
#     print("You are old")
#
# # 判断闰年
# year = int(input("请输入年份："))
# if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):
#     print("%d是闰年" % year)
# else:
#     print("%d不是闰年" % year)
#
# # a b c 比较大小
# a = int(input("请输入a:"))
# b = int(input("请输入b:"))
# c = int(input("请输入c:"))
# if a<b:
#     if a>c:
#         print("a is the largest")
#     else:
#         print("c is the largest")
# else:
#     if b>c:
#         print("b is the largest")
#     else:
#         print("c is the largest")
from itertools import count

# 计算器实现加减乘除
# num1 = float(input("请输入第一个数字："))
# num2 = float(input("请输入第二个数字："))
# op = input("请输入运算符：")
# if op == "+":
#     print(num1 + num2)
# elif op == "-":
#     print(num1 - num2)
# elif op == "*":
#     print(num1 * num2)
# elif op == "/":
#     print(num1 / num2)
# else:
#     print("输入错误")

# 打印一百以内3的倍数
# for i in range(1, 100 + 1):
#     if i % 3 == 0:
#         print(i, end="\t")


# from random import random, randint
# # 猜数字
# # random
# num = randint(1, 100)
# #print(num)
# while True:
#     guess= int(input("请输入一个数字："))
#     if guess>num:
#         print("猜大了")
#     elif guess<num:
#         print("猜小了")
#     else:
#         print("猜对了")
#     break


for i in range(1,100+1):
    if i%7 ==0  or str(i).find("7") != -1:
#    if i % 7 == 0 or str(i).count("7") > 0:
     print(i, end = "\t")


# 打印菱形
for i in range(1, 11 + 1, 2):
    print(("*" * i).center(11))
for i in range(9,0,-2):
    print(("*"*i).center(11))

#斐波那契数列
def fibonacci(n):
    if n == 0:
        return 0
    elif n == 1:
        return 1
    else:
        a, b = 0, 1
        for _ in range(2, n + 1):
            a, b = b, a + b
        return b

# 测试代码
for i in range(10):
    print(f"F({i}) = {fibonacci(i)}")

#打印水仙花数
# 打印所有的三位水仙花数
for num in range(100, 1000):
    # 分离出百位、十位和个位
    hundreds = num // 100
    tens = (num // 10) % 10
    ones = num % 10

    # 计算各位数字的立方和
    sum_of_cubes = hundreds ** 3 + tens ** 3 + ones ** 3

    # 判断是否为水仙花数
    if sum_of_cubes == num:
        print(num)
#打印菱形
def print_diamond(size):
    # 上半部分
    for i in range(size):
        # 打印空格
        print(' ' * (size - i - 1), end='')
        # 打印星号
        print('*' * (2 * i + 1))

    # 下半部分
    for i in range(size - 2, -1, -1):
        # 打印空格
        print(' ' * (size - i - 1), end='')
        # 打印星号
        print('*' * (2 * i + 1))


# 测试代码
size = 5
print_diamond(size)


#打印九九乘法表
# 打印九九乘法表
for i in range(1, 10):
    for j in range(1, i + 1):
        print(f"{j} * {i} = {i * j}", end='\t')
    print()  # 换行

#打印完数
def is_perfect_number(n):
    # 计算所有真因子的和
    sum_of_divisors = 0
    for i in range(1, n):
        if n % i == 0:
            sum_of_divisors += i

    # 判断是否为完数
    return sum_of_divisors == n


#打印质数
def is_prime(n):
    """检查一个数是否为质数"""
    if n <= 1:
        return False
    if n <= 3:
        return True
    if n % 2 == 0 or n % 3 == 0:
        return False
    i = 5
    while i * i <= n:
        if n % i == 0 or n % (i + 2) == 0:
            return False
        i += 6
    return True

# 打印1到100之间的所有质数
for num in range(1, 101):
    if is_prime(num):
        print(num)
#
